package com.hkyl.hospital.service.impl;

import com.hkyl.hospital.entity.PatientOperation;
import com.hkyl.hospital.mapper.PatientOperationMapper;
import com.hkyl.hospital.service.PatientMedicineService;
import com.hkyl.hospital.service.PatientOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author hyh
 * @date 2023/07/16 23:02:30
 */
@Service
@Transactional
public class PatientOperationServiceImpl implements PatientOperationService {

    @Autowired
    private PatientOperationMapper patientOperationMapper;
    @Autowired
    private PatientMedicineService patientMedicineService;

    @Override
    public Integer save(PatientOperation patientOperation) {
        Integer patientId = patientOperation.getPatientId();
        BigDecimal price = patientOperation.getPrice();
        Integer billId = patientMedicineService.addOrderAndUpdateBillCostPrice(patientId, "手术费", price);
        patientOperation.setBillId(billId);
        int rows = patientOperationMapper.insertSelective(patientOperation);
        return rows;
    }

}
